﻿using System;

using System.Collections.Generic;
using System.Xml;
using OpenGLES;
using System.IO;

namespace PFD
{
    public class TexturePoolReader
    {
        public static Dictionary<string, IRenderTexture> LoadFromXML(string sCurrentPath, XmlNodeList poolelements, IRenderDevice rd)
        {
            Dictionary<string, IRenderTexture> dict = new Dictionary<string, IRenderTexture>();

            foreach (XmlNode element in poolelements)
            {
                string idx = element.Attributes["ID"].Value;
                bool bTransparency = element.SelectSingleNode("TRANSPARENCY").InnerText.ToLower() == "no" ? false : true;
                string sPath = sCurrentPath + element.SelectSingleNode("RELATIVEPATH").InnerText;

                IRenderTexture t = rd.CreateTexture(sPath, bTransparency);

                dict.Add(idx, t);
            }

            return dict;
        }
    }

    public struct GlobalPoolContainer : IGlobalPoolContainer
    {

        public Dictionary<string, IRenderTexture> texturePool;

        #region IGlobalPoolContainer Members

        public IRenderTexture GetTexture(string szTexturename)
        {
            return texturePool[szTexturename];
        }

        #endregion
    }
}
